# -*- coding: utf-8 -*-
from datetime import timedelta
from jms.time_sensor.time_after_05_00 import time_after_05_00
from jms.ods.oms.yl_oms_oms_order import jms_ods__yl_oms_oms_order
from jms.dim.dim_sys_network_detail_dt import jms_dim__dim_sys_network_detail_dt
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dwd__dwd_order_detail_dt = SparkSqlOperator(
    task_id='jms_dwd__dwd_order_detail_dt',
    task_concurrency=1,
    pool_slots=2,
    #execution_timeout=timedelta(hours=1)
    #excel平均时长:1分8秒
    execution_timeout = timedelta(minutes=30),
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    master='yarn',
    name='jms_dwd__dwd_order_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/January/dwd_order_detail_dt/execute.hql',
    driver_memory='4G' , 
    driver_cores=2 , 
    executor_cores=2 , 
    executor_memory='4G' , 
    num_executors=8 , 
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 10 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G' , 
          'spark.sql.shuffle.partitions': 600,
          'spark.default.paralleism': 600,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 300,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 12,  # 每天生成 35 个分区
              'hive.exec.max.dynamic.partitions.pernode': 12,  # 每天生成 35 个分区
              },
)

jms_dwd__dwd_order_detail_dt << [
    jms_ods__yl_oms_oms_order,
    jms_dim__dim_sys_network_detail_dt,
    time_after_05_00,
]
